package cn.scnu.controller;

import cn.hutool.core.lang.tree.Tree;
import cn.scnu.common.model.PaginationData;
import cn.scnu.common.model.ResponseResult;
import cn.scnu.model.dto.W3dServiceInfoDTO;
import cn.scnu.model.dto.W3dServiceInfoUpdateDTO;
import cn.scnu.model.query.W3dServiceInfoQueryParam;
import cn.scnu.service.IW3dServiceInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 三维服务资源信息
 *
 * @author hqz
 * @className W3dServiceInfoController
 * @createTime 2024年12月11日 11:12:00
 */
@RestController
@RequestMapping("/w3dServiceInfo")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "三维服务资源信息")
public class W3dServiceInfoController {

    private final IW3dServiceInfoService w3dServiceInfoService;

    @ApiOperation(value = "根据id查询三维资源信息")
    @GetMapping("getW3dServiceInfoById")
    public ResponseResult<W3dServiceInfoDTO> getW3dServiceInfoById(@RequestParam String id) {
        return ResponseResult.success(w3dServiceInfoService.getW3dServiceInfoById(id));
    }

    @ApiOperation(value = "分页查询三维资源信息")
    @PostMapping("getW3dServiceInfoPage")
    public ResponseResult<PaginationData<W3dServiceInfoDTO>> getW3dServiceInfoPage(@RequestBody W3dServiceInfoQueryParam queryParam) {
        return ResponseResult.success(w3dServiceInfoService.getW3dServiceInfoPage(queryParam));
    }

    @ApiOperation(value = "新增一条三维资源信息")
    @PostMapping("insertW3dServiceInfo")
    public ResponseResult<Integer> insertW3dServiceInfo(@RequestBody @Validated W3dServiceInfoDTO w3dServiceInfoDTO) {
        return ResponseResult.success(w3dServiceInfoService.insertW3dServiceInfo(w3dServiceInfoDTO));
    }

    @ApiOperation(value = "更新一条三维资源信息")
    @PostMapping("updateW3dServiceInfo")
    public ResponseResult<Integer> updateW3dServiceInfo(@RequestBody W3dServiceInfoUpdateDTO w3dServiceInfoUpdateDTO) {
        return ResponseResult.success(w3dServiceInfoService.updateW3dServiceInfo(w3dServiceInfoUpdateDTO));
    }

    @ApiOperation(value = "删除一条三维资源信息")
    @PostMapping("deleteW3dServiceInfoById/{id}")
    public ResponseResult<Integer> deleteW3dServiceInfoById(@PathVariable String id) {
        return ResponseResult.success(w3dServiceInfoService.deleteW3dServiceInfoById(id));
    }

    @ApiOperation(value = "返回三维资源信息目录")
    @GetMapping("getW3dServiceInfoCatalogue")
    public ResponseResult<List<Tree<String>>> getW3dServiceInfoCatalogue() {
        return ResponseResult.success(w3dServiceInfoService.getW3dServiceInfoCatalogue());
    }

    @ApiOperation(value = "获取三维数据服务下载地址")
    @GetMapping("dataDownload")
    public String dataDownload(@RequestParam String sjmc, @RequestParam String da) {
        log.info("成功获取三维数据服务下载地址，数据名称：{}，流程id：{}", sjmc, da);
        return w3dServiceInfoService.dataDownload(sjmc, da);
    }

    @ApiOperation(value = "三维数据下载，下载后将文件进行删除")
    @GetMapping("dataDownload/{file_name}")
    public void dataDownload(@PathVariable("file_name") String fileName, HttpServletResponse response) {
        log.info("三维数据服务下载成功，文件名：", fileName);
        w3dServiceInfoService.dataDownload(fileName, response);
    }
}
